﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Threading;

namespace AutonomicComputingLibrary.MAPE.Monitor
{
    public class Monitor
    {
        private Analyze analyze;

          public Monitor()
          {

              Process app = System.Diagnostics.Process.GetCurrentProcess();

              app.PriorityClass = ProcessPriorityClass.High;
              


              analyze = new Analyze();

          }


          //to do  //should check to see if situation changes, maybe you could use the methiod that returns a string in execute
          //recheck
     


        //all utils must this alert and a checkup method infact you should make a base class
        //The RAM class is done 

        //tomorrow build Analyze class and write to xml - build xml file for each class the util namespace - done

      //done  //if no entries in file try in order and see which works best or you need to be with threshold whatever that is 

       //done //analysis should write to db and gather plans, and update the rank based off of increase

      //done  //Thursday build Plan class which should select plan from rankings - these will be  chop classes that it selects from - done

        //build a chop class that does something simple like finds programs that are not needed in memory and kills them

      //done  //Friday build exec class that writes to executes and writes to file

        

       //done //Build chop method for subsribe and bind to chop in a method as an arg do this in suscribe

       //done //allow user to create  mapping
       
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="MappingList">The chop class and the method to resolve issue. You can have several methods to resolve issues. </param>
        /// 
        /// //on start prep analyze pass it all members and classes
        /// //make sure each is a singleton so they don't duplicate
        public void Subscribe(dynamic obj, List<Tuple<dynamic,string>> MappingList )
        {
           
            analyze.InitConfig(obj.ToString(), MappingList);

            obj.Alert += new AlertHandler(HeardIt);
            obj.CheckUp();
        }


       


        /// <summary>
        /// On alert pass message to next stage
        /// </summary>
        /// <param name="m"></param>
        /// <param name="e"></param>
        private void HeardIt(dynamic obj, ACLAlert e)
            {
        
               analyze.Error(obj.ToString());
            }


       
            
        

        /// <summary>
        /// Pause the MAPE loop. Save obj state
        /// </summary>
          public void Stop() { }


      

    }
}
